<template>
	<view class="goods_details">
		<swiper indicator-dots="true" circular="true" autoplay="true">
			<swiper-item v-for="(item,index) in swipers" :key="index">
				<image :src="item"></image>
			</swiper-item>
		</swiper>

		<view class="box1">
			<view class="price">
				<text>￥{{productInfo.cPrice}}</text>
				<text>￥{{productInfo.oPrice}}</text>
			</view>
			<view class="goods_name">{{productInfo.goodsName}}</view>
		</view>
		<view class="line"></view>
		<view class="box2">
			<view>配置：{{productInfo.config}}</view>
			<view>已售：{{productInfo.amount}}件</view>
		</view>
		<view class="line"></view>
		<view class="box3">
			<view class="title">{{productInfo.title}}</view>
			<!-- 如果是HTML内容，选择使用富文本标签rich-text -->
			<view class="content">{{productInfo.content}}</view>
		</view>
		<view class="buy">
			<uni-goods-nav :fill="true" :options="options" :buttonGroup="buttonGroup" @click="onClick"
				@buttonClick="buttonClick" />
		</view>
	</view>
</template>

<script>
	// 使用uni-goods-nav 商品导航扩展组件
	import uniGoodsNav from '@/uni_modules/uni-goods-nav/components/uni-goods-nav/uni-goods-nav.vue'
	export default {
		data() {
			return {
				swipers: [],
				productInfo: {},
				options: [{
					icon: 'headphones',
					text: '客服'
				}, {
					icon: 'shop',
					text: '店铺',
					info: 2,
					infoBackgroundColor: '#007aff',
					infoColor: "red"
				}, {
					icon: 'cart',
					text: '购物车',
					info: 2
				}],
				buttonGroup: [{
						text: '加入购物车',
						backgroundColor: '#ff0000',
						color: '#fff'
					},
					{
						text: '立即购买',
						backgroundColor: '#ffa200',
						color: '#fff'
					}
				]
			}
		},
		onLoad(options) {
			console.log("查看商品的详细信息：", options.id)
			this.getSwipers(options.id);
			this.getProductDetailInfo(options.id)
		},
		components: {
			uniGoodsNav
		},
		methods: {
			getSwipers(productId) {
				// 实际场景应该是调用接口获取轮播图地址列表
				this.swipers = [
					"../../../static/img/1.jpg",
					"../../../static/img/2.jpg",
					"../../../static/img/3.jpg"
				];
			},
			getProductDetailInfo(productId) {
				// 实际场景应该是调用接口获取商品详情信息
				this.productInfo = {
					cPrice: 3455,
					oPrice: 4299,
					goodsName: "OPPO全新IQOO5青春版智能手机",
					config: "128G core I5",
					amount: 3499,
					title: "OPPO全新IQOO5青春版介绍",
					content: "OPPO全新IQOO5青春版OPPO全新IQOO5青春版OPPO全新IQOO5青春版OPPO全新IQOO5青春版OPPO全新IQOO5青春版"
				};
			},
			onClick(e) {
				uni.showToast({
					title: `点击${e.content.text}`,
					icon: 'none'
				})
			},
			buttonClick(e) {
				console.log(e)
				this.options[2].info++
			}
		}
	}
</script>

<style lang="scss">
	.goods_details {
		height: 700rpx;

		image {
			height: 100%;
			width: 100%;
		}

		.box1 {
			padding: 10px;

			.price {
				font-size: 35rpx;
				color: #b50e03;
				line-height: 80rpx;

				text:nth-child(2) {
					color: #ccc;
					font-size: 25rpx;
					margin-left: 17rpx;
					text-decoration: line-through;
				}
			}

			.goods_name {
				font-size: 32rpx;
				line-height: 60rpx;
			}
		}

		.line {
			height: 10rpx;
			width: 750rpx;
			background: #eee;
		}

		.box2 {
			padding: 10px;
			font-size: 32rpx;
			line-height: 60rpx;
		}

		.box3 {
			// 给buy预留空间
			padding-bottom: 50px;
			.title {
				font-size: 32rpx;
				padding-left: 10rpx;
				border-bottom: 1px solid #eee;
				line-height: 70rpx;
			}

			.content {
				font-size: 28rpx;
				padding: 10rpx;
			}
		}
		.buy {
			position: fixed;
			bottom: 0;
			width: 100%;
		}
	}
</style>
